<!DOCTYPE html>
<html>
<head>
<script>
(function(){
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https') {
        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
    }
    else {
        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>
<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?d890b1f16fb364253e79c5bb20225c3a";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>


    

    

    
<!-- Baidu Tongji -->
<script>var _hmt = _hmt || []</script>
<script async src="//hm.baidu.com/hm.js?busuanzi_value_site_uv"></script>
<!-- End Baidu Tongji -->




    <meta charset="utf-8">
    <meta name="baidu-site-verification" content="FYMCShbUK8" />
    <meta name="baidu-site-verification" content="ZYRF7OxQRW" />
    <meta name="baidu-site-verification" content="cHSqtjI0PN" />
    <meta name="baidu-site-verification" content="cHSqtjI0PN" />
    <meta name="baidu-site-verification" content="cHSqtjI0PN" />
    
    
    <link rel="canonical" href="https://hhardyy.com/2018/09/21/redux、react-router/">
    
    
    <title>redux、react-router | 小方块 - hhardyy.com | 复杂的坑+归其原理+了解实现规则===解决？解决成功：加油解决成功;</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    
    <meta name="theme-color" content="#958e93">
    
    
    <meta name="keywords" content="react,react-router,redux,react-redux,装饰器,中间件">
    <meta name="description" content="redux状态管理，不光react可以用，vue，angular都可以用。">
<meta name="keywords" content="react,react-router,redux,react-redux,装饰器,中间件">
<meta property="og:type" content="article">
<meta property="og:title" content="redux、react-router">
<meta property="og:url" content="http://yoursite.com/2018/09/21/redux、react-router/index.html">
<meta property="og:site_name" content="小方块 - hhardyy.com">
<meta property="og:description" content="redux状态管理，不光react可以用，vue，angular都可以用。">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="http://yoursite.com/images/reduxImg/111.png">
<meta property="og:image" content="http://yoursite.com/images/reduxImg/1.JPG">
<meta property="og:image" content="http://yoursite.com/images/reduxImg/2.gif">
<meta property="og:image" content="http://yoursite.com/images/reduxImg/3.gif">
<meta property="og:image" content="http://yoursite.com/images/reduxImg/22.gif">
<meta property="og:image" content="http://yoursite.com/images/reduxImg/lu.gif">
<meta property="og:updated_time" content="2020-01-13T15:22:58.746Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="redux、react-router">
<meta name="twitter:description" content="redux状态管理，不光react可以用，vue，angular都可以用。">
<meta name="twitter:image" content="http://yoursite.com/images/reduxImg/111.png">
    
        <link rel="alternate" type="application/atom+xml" title="小方块 - hhardyy.com" href="/atom.xml">
    
    <link rel="shortcut icon" href="/hardyfavicon.ico">
    <link rel="stylesheet" href="//unpkg.com/hexo-theme-material-indigo@latest/css/style.css">
    <script>window.lazyScripts=[]</script>

    <!-- custom head -->
    

</head>

<body>
    <div id="loading" class="active"></div>

    <aside id="menu" class="hide" >
  <div class="inner flex-row-vertical">
    <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="menu-off">
        <i class="icon icon-lg icon-close"></i>
    </a>
    <div class="brand-wrap" style="background-image:url(/img/paulGraham.jpg)">
      <div class="brand" style="background-color:#4154b2">
        <a href="/" class="avatar waves-effect waves-circle waves-light">
          <img src="/img/avatar.jpg">
        </a>
        <hgroup class="introduce">
          <h5 class="nickname">BingZhenhuang</h5>
          <a href="mailto:huangbingzhen@hhardyy.com" title="huangbingzhen@hhardyy.com" class="mail">huangbingzhen@hhardyy.com</a>
        </hgroup>
      </div>
    </div>
    <div class="scroll-wrap flex-col">
      <ul class="nav">
        
            <li class="waves-block waves-effect">
              <a href="/"  >
                <i class="icon icon-lg icon-home"></i>
                主页
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/archives"  >
                <i class="icon icon-lg icon-archives"></i>
                所有文章
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/tags"  >
                <i class="icon icon-lg icon-tags"></i>
                标签
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="https://github.com/HHardyy" target="_blank" >
                <i class="icon icon-lg icon-github"></i>
                Github
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="https://juejin.im/user/59a26f926fb9a02487553b04"  >
                <i class="icon icon-lg icon-pencil"></i>
                掘金-圳
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="https://segmentfault.com/u/hhardyy"  >
                <i class="icon icon-lg icon-comments"></i>
                Segmentfault
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="https://codepen.io/HHardyy/" target="_blank" >
                <i class="icon icon-lg icon-codepen"></i>
                Codepen
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/ZhenSolive/find.html" target="_blank" >
                <i class="icon icon-lg icon-globe"></i>
                原生直播间
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/hero/judge.html" target="_blank" >
                <i class="icon icon-lg icon-cloud"></i>
                原生小悟空
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/airPlay/HHardyy_PC.html" target="_blank" >
                <i class="icon icon-lg icon-camera"></i>
                原生飞机大战（PC）
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="https://www.freecodecamp.cn/hhardyy" target="_blank" >
                <i class="icon icon-lg icon-leaf"></i>
                Freecodecamp
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/友情链接"  >
                <i class="icon icon-lg icon-link"></i>
                友链
              </a>
            </li>
        
      </ul>
    </div>
  </div>
</aside>

    <main id="main">
        <header class="top-header" id="header">
    <div class="flex-row">
        <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light on" id="menu-toggle">
          <i class="icon icon-lg icon-navicon"></i>
        </a>
        <div class="flex-col header-title ellipsis">redux、react-router</div>
        
        <div class="search-wrap" id="search-wrap">
            <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="back">
                <i class="icon icon-lg icon-chevron-left"></i>
            </a>
            <input type="text" id="key" class="search-input" autocomplete="off" placeholder="输入感兴趣的关键字">
            <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="search">
                <i class="icon icon-lg icon-search"></i>
            </a>
        </div>
        
        
        <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="menuShare">
            <i class="icon icon-lg icon-share-alt"></i>
        </a>
        
    </div>
</header>
<header class="content-header post-header">

    <div class="container fade-scale">
        <h1 class="title">redux、react-router</h1>
        <h5 class="subtitle">
            
                <time datetime="2018-09-21T04:29:36.000Z" itemprop="datePublished" class="page-time">
  2018-09-21
</time>


            
        </h5>
    </div>

    


</header>


<div class="container body-wrap">
    
    <aside class="post-widget">
        <nav class="post-toc-wrap" id="post-toc">
            <h4>TOC</h4>
            <ol class="post-toc"><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#状态管理"><span class="post-toc-number">1.</span> <span class="post-toc-text">状态管理</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#redux异步"><span class="post-toc-number">2.</span> <span class="post-toc-text">redux异步</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#react连接redux状态管理操作"><span class="post-toc-number">3.</span> <span class="post-toc-text">react连接redux状态管理操作</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#装饰器"><span class="post-toc-number">4.</span> <span class="post-toc-text">装饰器</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#合并所有reducer"><span class="post-toc-number">5.</span> <span class="post-toc-text">合并所有reducer</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#react-router4"><span class="post-toc-number">6.</span> <span class="post-toc-text">react-router4</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#安装"><span class="post-toc-number">6.1.</span> <span class="post-toc-text">安装</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#React-Router中的HashRouter与BrowserRouter"><span class="post-toc-number">6.2.</span> <span class="post-toc-text">React-Router中的HashRouter与BrowserRouter</span></a></li></ol></li></ol>
        </nav>
    </aside>
    
<article id="post-redux、react-router"
  class="post-article article-type-post fade" itemprop="blogPost">

    <div class="post-card">
        <h1 class="post-card-title">redux、react-router</h1>
        <div class="post-meta">
            <time class="post-time" title="2018-09-21 12:29:36" datetime="2018-09-21T04:29:36.000Z"  itemprop="datePublished">2018-09-21</time>

            


            

        </div>
        <div class="post-content" id="post-content" itemprop="postContent">
            <p>redux状态管理，不光react可以用，vue，angular都可以用。</p>
<p><iframe frameborder="no" border="0" marginwidth="0" marginheight="0" width="330" height="86" src="//music.163.com/outchain/player?type=2&id=460318201&auto=0&height=66"></iframe><br><a id="more"></a></p>
<blockquote>
<p>Redux 本身很简单。当使用普通对象来描述应用的 state 时。这个对象就像 “Model”，区别是它并没有 setter（修改器方法）。因此其它的代码不能随意修改它，造成难以复现的 bug。<br>要想更新 state 中的数据，你需要发起一个 action。Action 就是一个普通 JavaScript对象（注意到没，这儿没有任何魔法？）用来描述发生了什么。强制使用action来描述所有变化带来的好处是可以清晰<br>地知道应用中到底发生了什么。如果一些东西改变了，就可以知道为什么变。action就像是描述发生了什么的指示器。最终，为了把action和state串起来，开发一些函数，这就是reducer。再次地，没有任何魔<br>法，reducer 只是一个接收 state 和 action，并返回新的 state 的函数。 对于大的应用来说，不大可能仅仅只写一个这样的函数，所以我们编写很多小函数来分别管理state的一部分,再开发一个reducer<br>调用这两个 reducer，进而来管理整个应用的 state,差不多就是 Redux 思想的全部。</p>
</blockquote>
<h3 id="状态管理"><a href="#状态管理" class="headerlink" title="状态管理"></a>状态管理</h3><p>一张图了解redux工作<br><figure class="image-bubble">
                <div class="img-lightbox">
                    <div class="overlay"></div>
                    <img src="/images/reduxImg/111.png" alt="redux" title="">
                </div>
                <div class="image-caption">redux</div>
            </figure><br>例如初始一个状态管理，这是我建好的项目里面的三个js,index.js负责渲染，App.js是个组件，index.redux.js负责状态管理<br>index.js<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">import</span> React <span class="keyword">from</span> <span class="string">'react'</span></div><div class="line"><span class="keyword">import</span> ReactDom <span class="keyword">from</span> <span class="string">'react-dom'</span></div><div class="line"><span class="keyword">import</span> App <span class="keyword">from</span> <span class="string">'./App'</span></div><div class="line"><span class="keyword">import</span> &#123; createStore &#125; <span class="keyword">from</span> <span class="string">'redux'</span></div><div class="line"><span class="keyword">import</span> &#123; center &#125; <span class="keyword">from</span> <span class="string">'./index.redux'</span></div><div class="line"><span class="keyword">const</span> store=createStore(center)</div><div class="line"></div><div class="line">ReactDom.render(</div><div class="line">    &lt;App store=&#123;store&#125;/&gt;,</div><div class="line">    <span class="built_in">document</span>.getElementById(<span class="string">'root'</span>)</div><div class="line">)</div></pre></td></tr></table></figure></p>
<p>App.js<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">import</span> React,&#123;Component&#125; <span class="keyword">from</span> <span class="string">'react'</span></div><div class="line"></div><div class="line"><span class="class"><span class="keyword">class</span> <span class="title">App</span> <span class="keyword">extends</span> <span class="title">Component</span></span>&#123;</div><div class="line">    <span class="keyword">constructor</span>(props)&#123;</div><div class="line">        <span class="keyword">super</span>(props);</div><div class="line">    &#125;</div><div class="line">    render()&#123;</div><div class="line">        <span class="keyword">const</span> sTore=<span class="keyword">this</span>.props.store;</div><div class="line">        <span class="keyword">const</span> data=sTore.getState();</div><div class="line">        <span class="keyword">return</span> <span class="xml"><span class="tag">&lt;<span class="name">h1</span>&gt;</span>hellow app,现在有菜鸡$&#123;data&#125;只<span class="tag">&lt;/<span class="name">h1</span>&gt;</span></span></div><div class="line">    &#125;</div><div class="line">&#125;</div><div class="line"><span class="keyword">export</span> <span class="keyword">default</span> App</div></pre></td></tr></table></figure></p>
<p>index.redux.js<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">const</span> ADD_CAI=<span class="string">'加菜鸡'</span>;</div><div class="line"><span class="keyword">const</span> REMOVE_CAI=<span class="string">'减菜鸡'</span></div><div class="line"></div><div class="line"><span class="keyword">export</span> <span class="function"><span class="keyword">function</span> <span class="title">center</span>(<span class="params">state=<span class="number">0</span>,action</span>)</span>&#123;</div><div class="line">    <span class="keyword">switch</span>(action.type)&#123;</div><div class="line">        <span class="keyword">case</span> ADD_CAI:</div><div class="line">            <span class="keyword">return</span> state+<span class="number">1</span>;</div><div class="line">        <span class="keyword">case</span> REMOVE_CAI:</div><div class="line">            <span class="keyword">return</span> state<span class="number">-1</span>;</div><div class="line">        <span class="keyword">default</span> :</div><div class="line">            <span class="keyword">return</span> <span class="number">10</span></div><div class="line">    &#125;</div><div class="line">&#125;</div><div class="line"></div><div class="line"><span class="comment">//action creator专门创建action</span></div><div class="line"><span class="keyword">export</span> <span class="function"><span class="keyword">function</span> <span class="title">addCai</span>(<span class="params"></span>)</span>&#123;</div><div class="line">    <span class="keyword">return</span> &#123;<span class="attr">type</span>:ADD_CAI&#125;</div><div class="line">&#125;</div><div class="line"><span class="keyword">export</span> <span class="function"><span class="keyword">function</span> <span class="title">removeCai</span>(<span class="params"></span>)</span>&#123;</div><div class="line">    <span class="keyword">return</span> &#123;<span class="attr">type</span>:REMOVE_CAI&#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure></p>
<figure class="image-bubble">
                <div class="img-lightbox">
                    <div class="overlay"></div>
                    <img src="/images/reduxImg/1.JPG" alt="这是初始的一个状态" title="">
                </div>
                <div class="image-caption">这是初始的一个状态</div>
            </figure>  
<p>改变状态的话，在App.js里面导入在index.redux.js里头定义的addCai，removeCai方法，然后添加两个按钮用来触发<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">&lt;h1&gt;hellow app,现在有菜鸡$&#123;data&#125;只&lt;<span class="regexp">/h1&gt;</span></div><div class="line"><span class="regexp">&lt;button onClick=&#123;()=&gt;store.dispatch(addCai())&#125;&gt;添加一只菜鸡&lt;/</span>button&gt;</div><div class="line">&lt;button onClick=&#123;()=&gt;store.dispatch(removeCai())&#125;&gt;菜死一只菜鸡&lt;<span class="regexp">/button&gt;</span></div></pre></td></tr></table></figure></p>
<p>这时候执行的话，其实状态已经改变了但是h1里面的数值没有改变，原因是状态虽然改变了，但是没有刷新，所以页面显示还是年轻的模样，只需要在index.js里面执行一下，store.subs<br>cribe(render)，意思就是把render重新执行一下，这时候状态改变就可以了<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="keyword">function</span> <span class="title">render</span>(<span class="params"></span>)</span>&#123;</div><div class="line">    ReactDom.render(</div><div class="line">        &lt;App store=&#123;store&#125;/&gt;,</div><div class="line">        <span class="built_in">document</span>.getElementById(<span class="string">'root'</span>)</div><div class="line">    )</div><div class="line">&#125;</div><div class="line">render()</div><div class="line"><span class="comment">//状态改变之后执行一下render</span></div><div class="line">store.subscribe(render)</div></pre></td></tr></table></figure></p>
<figure class="image-bubble">
                <div class="img-lightbox">
                    <div class="overlay"></div>
                    <img src="/images/reduxImg/2.gif" alt="render" title="">
                </div>
                <div class="image-caption">render</div>
            </figure>  
<p>当然，也可以把App.js里头import的两个方法转移到index.js，然后通过给子组件传值的方式传给App.js，这样代码看起来可能更和谐。</p>
<h3 id="redux异步"><a href="#redux异步" class="headerlink" title="redux异步"></a>redux异步</h3><p>redux默认只处理同步，异步需要中间件redux-thunk<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">npm install redux-thunk --save</div></pre></td></tr></table></figure></p>
<p>异步中间件使用，在index.js里头<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">import</span> &#123; createStore,applyMiddleware &#125; <span class="keyword">from</span> <span class="string">'redux'</span></div><div class="line"><span class="keyword">import</span> thunk <span class="keyword">from</span> <span class="string">'redux-thunk'</span></div><div class="line"></div><div class="line"><span class="keyword">const</span> store=createStore(</div><div class="line">	center,</div><div class="line">	applyMiddleware(thunk)</div><div class="line">)</div></pre></td></tr></table></figure></p>
<p>这时候就可以异步了，比如在index.redux.js里面模拟一个异步操作testAsync，然后在App.js里面添加一个button用来触发testAsync。<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">&lt;button onClick=&#123;()=&gt;store.dispatch(testAsync())&#125;&gt;凌迟处死一只菜鸡&lt;<span class="regexp">/button&gt;</span></div></pre></td></tr></table></figure></p>
<figure class="image-bubble">
                <div class="img-lightbox">
                    <div class="overlay"></div>
                    <img src="/images/reduxImg/3.gif" alt="render" title="">
                </div>
                <div class="image-caption">render</div>
            </figure>  
<h3 id="react连接redux状态管理操作"><a href="#react连接redux状态管理操作" class="headerlink" title="react连接redux状态管理操作"></a>react连接redux状态管理操作</h3><p>将render函数改成<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">import</span> &#123; Provider &#125; <span class="keyword">from</span> <span class="string">'react-redux'</span></div><div class="line">ReactDom.render(</div><div class="line">     (</div><div class="line">        &lt;Provider store=&#123;store&#125; &gt;</div><div class="line">            &lt;App/&gt;</div><div class="line">        &lt;<span class="regexp">/Provider&gt;</span></div><div class="line"><span class="regexp">     ),</span></div><div class="line"><span class="regexp">    document.getElementById('root'),</span></div><div class="line"><span class="regexp">)</span></div></pre></td></tr></table></figure></p>
<p>App.js里面导入connect以及index.redux里头的方法，这时候button里面的onClick事件处理函数直接可以写成{函数名}的形式，因为它这时候所有的数据都是直接从外部传进来的，所有的数据都是由index.react.js控制<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">import</span> &#123; connect &#125; <span class="keyword">from</span> <span class="string">'react-redux'</span></div><div class="line"><span class="keyword">import</span> &#123;addCai,removeCai,testAsync&#125; <span class="keyword">from</span> <span class="string">'./index.redux'</span></div><div class="line"><span class="class"><span class="keyword">class</span> <span class="title">App</span> <span class="keyword">extends</span> <span class="title">Component</span></span>&#123;</div><div class="line">    <span class="keyword">constructor</span>(props)&#123;</div><div class="line">        <span class="keyword">super</span>(props);</div><div class="line">    &#125;</div><div class="line">    render()&#123;</div><div class="line">        <span class="keyword">const</span> data=<span class="keyword">this</span>.props.num;</div><div class="line">        <span class="keyword">const</span> addCai=<span class="keyword">this</span>.props.addCai;</div><div class="line">        <span class="keyword">const</span> removeCai=<span class="keyword">this</span>.props.removeCai;</div><div class="line">        <span class="keyword">const</span> testAsync=<span class="keyword">this</span>.props.testAsync;</div><div class="line">        <span class="keyword">return</span> (</div><div class="line">            &lt;div&gt;</div><div class="line">                &lt;h1&gt;hellow app,现在有菜鸡&#123;data&#125;只&lt;<span class="regexp">/h1&gt;</span></div><div class="line"><span class="regexp">                &lt;button onClick=&#123;addCai&#125;&gt;添加一只菜鸡&lt;/</span>button&gt;</div><div class="line">                &lt;button onClick=&#123;removeCai&#125;&gt;菜死一只菜鸡&lt;<span class="regexp">/button&gt;</span></div><div class="line"><span class="regexp">                &lt;button onClick=&#123;testAsync&#125;&gt;凌迟处死一只菜鸡&lt;/</span>button&gt;</div><div class="line">            &lt;<span class="regexp">/div&gt;</span></div><div class="line"><span class="regexp">        )</span></div><div class="line"><span class="regexp">    &#125;</span></div><div class="line"><span class="regexp">&#125;</span></div><div class="line"><span class="regexp"></span></div><div class="line"><span class="regexp">const mapStateToProps=(state)=&gt;&#123;</span></div><div class="line"><span class="regexp">    return &#123; num: state&#125;</span></div><div class="line"><span class="regexp">&#125;</span></div><div class="line"><span class="regexp"></span></div><div class="line"><span class="regexp">const actionCreators= &#123;addCai,removeCai,testAsync&#125;</span></div><div class="line"><span class="regexp">  </span></div><div class="line"><span class="regexp">App=connect(mapStateToProps,actionCreators)(App)</span></div><div class="line"><span class="regexp">export default App</span></div></pre></td></tr></table></figure></p>
<p>connect的第一个参数，把state给到props，第二个参数也给到props，也就是属性和方法<br><figure class="image-bubble">
                <div class="img-lightbox">
                    <div class="overlay"></div>
                    <img src="/images/reduxImg/22.gif" alt="react-redux" title="">
                </div>
                <div class="image-caption">react-redux</div>
            </figure>  </p>
<h3 id="装饰器"><a href="#装饰器" class="headerlink" title="装饰器"></a>装饰器</h3><p>用装饰器之前先装一下这个插件<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">npm install babel-plugin-transform-decorators-legacy --save</div></pre></td></tr></table></figure></p>
<p>然后在项目的package.json里面添加<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">&#123;</div><div class="line">  <span class="string">"plugins"</span>: [</div><div class="line">    [<span class="string">"@babel/plugin-proposal-decorators"</span>, &#123; <span class="string">"legacy"</span>: <span class="literal">true</span> &#125;],</div><div class="line">  ]</div><div class="line">&#125;</div></pre></td></tr></table></figure></p>
<p>然后就可以做出这样的改变<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">const</span> mapStateToProps=<span class="function">(<span class="params">state</span>)=&gt;</span>&#123;</div><div class="line">    <span class="keyword">return</span> &#123; <span class="attr">num</span>: state&#125;</div><div class="line">&#125;</div><div class="line"><span class="keyword">const</span> actionCreators= &#123;addCai,removeCai,testAsync&#125;</div><div class="line">App=connect(mapStateToProps,actionCreators)(App)</div><div class="line"><span class="comment">//==》</span></div><div class="line">@connect(</div><div class="line">    state=&gt;(&#123;<span class="attr">num</span>:state&#125;),<span class="comment">//属性</span></div><div class="line">    &#123;addCai,removeCai,testAsync&#125; <span class="comment">//方法</span></div><div class="line">)</div></pre></td></tr></table></figure></p>
<h3 id="合并所有reducer"><a href="#合并所有reducer" class="headerlink" title="合并所有reducer"></a>合并所有reducer</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">import</span> combineReducers <span class="keyword">from</span> <span class="string">'redux'</span></div><div class="line"><span class="keyword">import</span> AA <span class="keyword">from</span> aa.redux.js</div><div class="line"><span class="keyword">import</span> BB <span class="keyword">from</span> aa.redux.js</div><div class="line">combineReducers(&#123;AA,BB&#125;)</div></pre></td></tr></table></figure>
<h3 id="react-router4"><a href="#react-router4" class="headerlink" title="react-router4"></a>react-router4</h3><blockquote>
<p>react-router4是全新的版本，和之前的版本不兼容，浏览器和react-native均兼容和vue一样，React开发单页应用必备，践行路由即组件的概念比如：动态路由，Route，Link，Switch</p>
<h4 id="安装"><a href="#安装" class="headerlink" title="安装"></a>安装</h4><figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">npm install react-router-dom --save</div></pre></td></tr></table></figure>
</blockquote>
<p>react-router-dom作为浏览器的路由<br>简单的路由例子<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">import</span> React <span class="keyword">from</span> <span class="string">'react'</span></div><div class="line"><span class="keyword">import</span> ReactDom <span class="keyword">from</span> <span class="string">'react-dom'</span></div><div class="line"><span class="keyword">import</span> &#123; createStore,applyMiddleware,compose &#125; <span class="keyword">from</span> <span class="string">'redux'</span></div><div class="line"><span class="keyword">import</span> thunk <span class="keyword">from</span> <span class="string">'redux-thunk'</span></div><div class="line"><span class="keyword">import</span> &#123; Provider &#125; <span class="keyword">from</span> <span class="string">'react-redux'</span></div><div class="line"><span class="keyword">import</span> App <span class="keyword">from</span> <span class="string">'./App'</span></div><div class="line"><span class="keyword">import</span> &#123; center &#125; <span class="keyword">from</span> <span class="string">'./index.redux'</span></div><div class="line"></div><div class="line"><span class="keyword">import</span> &#123; BrowserRouter,Route,Link &#125; <span class="keyword">from</span> <span class="string">'react-router-dom'</span></div><div class="line"></div><div class="line"><span class="keyword">const</span> store=createStore(center,compose(</div><div class="line">    applyMiddleware(thunk),</div><div class="line">    <span class="built_in">window</span>.devToolsExtension? <span class="built_in">window</span>.devToolsExtension():<span class="function"><span class="params">()</span>=&gt;</span>&#123;&#125;</div><div class="line">))<span class="comment">//异步中间件</span></div><div class="line"></div><div class="line"><span class="function"><span class="keyword">function</span> <span class="title">Cai2</span>(<span class="params"></span>)</span>&#123;</div><div class="line">    <span class="keyword">return</span> <span class="xml"><span class="tag">&lt;<span class="name">h1</span>&gt;</span>hwllo this is Cai2<span class="tag">&lt;/<span class="name">h1</span>&gt;</span></span></div><div class="line">&#125;</div><div class="line"><span class="function"><span class="keyword">function</span> <span class="title">Cai3</span>(<span class="params"></span>)</span>&#123;</div><div class="line">    <span class="keyword">return</span> <span class="xml"><span class="tag">&lt;<span class="name">h1</span>&gt;</span>hello this is Cai3<span class="tag">&lt;/<span class="name">h1</span>&gt;</span></span></div><div class="line">&#125;</div><div class="line"></div><div class="line"> ReactDom.render(</div><div class="line">     (</div><div class="line">        &lt;Provider store=&#123;store&#125; &gt;</div><div class="line">            &lt;BrowserRouter&gt;</div><div class="line">                &lt;div&gt;</div><div class="line">                &lt;ul&gt;</div><div class="line">                    &lt;li&gt;</div><div class="line">                        &lt;Link to=<span class="string">"/"</span>&gt;第一只菜鸡&lt;<span class="regexp">/Link&gt;</span></div><div class="line"><span class="regexp">                    &lt;/</span>li&gt;</div><div class="line">                    &lt;li&gt;</div><div class="line">                        &lt;Link to=<span class="string">"cai2"</span>&gt;第二只菜鸡&lt;<span class="regexp">/Link&gt;</span></div><div class="line"><span class="regexp">                    &lt;/</span>li&gt;</div><div class="line">                    &lt;li&gt;</div><div class="line">                        &lt;Link to=<span class="string">"cai3"</span>&gt;第三只菜鸡&lt;<span class="regexp">/Link&gt;</span></div><div class="line"><span class="regexp">                    &lt;/</span>li&gt;</div><div class="line">                &lt;<span class="regexp">/ul&gt;</span></div><div class="line"><span class="regexp">                &lt;Route path="/</span><span class="string">" component=&#123;App&#125;&gt;&lt;/Route&gt;</span></div><div class="line"><span class="string">                &lt;Route path="</span>/cai2<span class="string">" component=&#123;Cai2&#125;&gt;&lt;/Route&gt;</span></div><div class="line"><span class="string">                &lt;Route path="</span>/cai3<span class="string">" component=&#123;Cai3&#125;&gt;&lt;/Route&gt;</span></div><div class="line"><span class="string">                &lt;/div&gt;</span></div><div class="line"><span class="string">            &lt;/BrowserRouter&gt;</span></div><div class="line"><span class="string">        &lt;/Provider&gt;</span></div><div class="line"><span class="string">     ),</span></div><div class="line"><span class="string">    document.getElementById('root'),</span></div><div class="line"><span class="string">)</span></div></pre></td></tr></table></figure></p>
<figure class="image-bubble">
                <div class="img-lightbox">
                    <div class="overlay"></div>
                    <img src="/images/reduxImg/lu.gif" alt="run" title="">
                </div>
                <div class="image-caption">run</div>
            </figure>  
<p>但是有个问题，就是点Cai2的时候，组件App也渲染出来，是因为它path匹配的时候根目录是/，而/cai2，/cai3也是有/<br>，所以都会显示，它其实是个正则匹配，这时候可以选择加一个exact进行完全匹配，就可以了。</p>
<p><route path="/" exact="" component="{App}"></route><br>假如要添加一个地址跳转错误的友好404，就像这样<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">&lt;Route path=<span class="string">"/:localtion"</span> component=&#123;Wrong&#125;&gt;<span class="xml"><span class="tag">&lt;/<span class="name">Route</span>&gt;</span></span></div></pre></td></tr></table></figure></p>
<p>Redirect：默认页面打开加载某个组件或者强制加载某个组件<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">&lt;Redirect to=<span class="string">"/"</span>&gt;<span class="xml"><span class="tag">&lt;/<span class="name">Redirect</span>&gt;</span></span></div></pre></td></tr></table></figure></p>
<p>Switch：只渲染命中的第一个组件<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">&lt;Switch&gt;</div><div class="line">&lt;Route path=<span class="string">"/"</span> component=&#123;App&#125;&gt;<span class="xml"><span class="tag">&lt;/<span class="name">Route</span>&gt;</span></span></div><div class="line">&lt;Route path=<span class="string">"/:localtion"</span> component=&#123;Wrong&#125;&gt;<span class="xml"><span class="tag">&lt;/<span class="name">Route</span>&gt;</span></span></div><div class="line">&lt;Route path=<span class="string">"/cai2"</span> component=&#123;Cai2&#125;&gt;<span class="xml"><span class="tag">&lt;/<span class="name">Route</span>&gt;</span></span></div><div class="line">&lt;Route path=<span class="string">"/cai3"</span> component=&#123;Cai3&#125;&gt;<span class="xml"><span class="tag">&lt;/<span class="name">Route</span>&gt;</span></span></div><div class="line">&lt;<span class="regexp">/Switch&gt;</span></div></pre></td></tr></table></figure></p>
<h4 id="React-Router中的HashRouter与BrowserRouter"><a href="#React-Router中的HashRouter与BrowserRouter" class="headerlink" title="React-Router中的HashRouter与BrowserRouter"></a>React-Router中的HashRouter与BrowserRouter</h4><p>以下解释的前提是你要懂hash地址，假如有一个 Link 标签，跳转到 /hhardyy<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">BrowserRouter： http:<span class="comment">//localhost:8080/hhardyy</span></div><div class="line">HashRouter： http:<span class="comment">//localhost:8080/#/hhardyy</span></div></pre></td></tr></table></figure></p>
<p>如果有服务器端的动态支持，建议使用 BrowserRouter，否则建议使用 HashRouter。原因在于，如果是单纯的静态文件，假如路径从 / 切换到 /hhardyy 后，此时刷新页面，页面将无法正常访问。<br>二者的替换方法很简单，在import的时候，将 BrowserRouter 修改为 HashRouter 就可以了，不需要修改其他东西。</p>

        </div>

        <blockquote class="post-copyright">
    <div class="content">
        
<span class="post-time">
    最后更新时间：<time datetime="2020-01-13T15:22:58.746Z" itemprop="dateUpdated">2020-01-13 23:22:58</time>
</span><br>


        
        谢谢浏览，我会继续努力的，示例：<a href="/2018/09/21/redux、react-router/" target="_blank" rel="external">http://yoursite.com/2018/09/21/redux、react-router/</a>
        
    </div>
    <footer>
        <a href="http://yoursite.com">
            <img src="/img/avatar.jpg" alt="BingZhenhuang">
            BingZhenhuang
        </a>
    </footer>
</blockquote>

        
<div class="page-reward">
    <a id="rewardBtn" href="javascript:;" class="page-reward-btn waves-effect waves-circle waves-light">赏</a>
</div>



        <div class="post-footer">
            
	<ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/react/">react</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/react-redux/">react-redux</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/react-router/">react-router</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/redux/">redux</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/中间件/">中间件</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/装饰器/">装饰器</a></li></ul>


            
<div class="page-share-wrap">
    

<div class="page-share" id="pageShare">
    <ul class="reset share-icons">
      <li>
        <a class="weibo share-sns" target="_blank" href="http://service.weibo.com/share/share.php?url=http://yoursite.com/2018/09/21/redux、react-router/&title=《redux、react-router》 — 小方块 - hhardyy.com&pic=http://yoursite.com/img/avatar.jpg" data-title="微博">
          <i class="icon icon-weibo"></i>
        </a>
      </li>
      <li>
        <a class="weixin share-sns wxFab" href="javascript:;" data-title="微信">
          <i class="icon icon-weixin"></i>
        </a>
      </li>
      <li>
        <a class="qq share-sns" target="_blank" href="http://connect.qq.com/widget/shareqq/index.html?url=http://yoursite.com/2018/09/21/redux、react-router/&title=《redux、react-router》 — 小方块 - hhardyy.com&source=redux状态管理，不光react可以用，vue，angular都可以用。
" data-title=" QQ">
          <i class="icon icon-qq"></i>
        </a>
      </li>
      <li>
        <a class="facebook share-sns" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=http://yoursite.com/2018/09/21/redux、react-router/" data-title=" Facebook">
          <i class="icon icon-facebook"></i>
        </a>
      </li>
      <li>
        <a class="twitter share-sns" target="_blank" href="https://twitter.com/intent/tweet?text=《redux、react-router》 — 小方块 - hhardyy.com&url=http://yoursite.com/2018/09/21/redux、react-router/&via=http://yoursite.com" data-title=" Twitter">
          <i class="icon icon-twitter"></i>
        </a>
      </li>
      <li>
        <a class="google share-sns" target="_blank" href="https://plus.google.com/share?url=http://yoursite.com/2018/09/21/redux、react-router/" data-title=" Google+">
          <i class="icon icon-google-plus"></i>
        </a>
      </li>
    </ul>
 </div>



    <a href="javascript:;" id="shareFab" class="page-share-fab waves-effect waves-circle">
        <i class="icon icon-share-alt icon-lg"></i>
    </a>
</div>



        </div>
    </div>

    
<nav class="post-nav flex-row flex-justify-between">
  
    <div class="waves-block waves-effect prev">
      <a href="/2018/10/05/浅谈高阶组件/" id="post-prev" class="post-nav-link">
        <div class="tips"><i class="icon icon-angle-left icon-lg icon-pr"></i> Prev</div>
        <h4 class="title">浅谈高阶组件</h4>
      </a>
    </div>
  

  
    <div class="waves-block waves-effect next">
      <a href="/2018/09/17/密码算法实验/" id="post-next" class="post-nav-link">
        <div class="tips">Next <i class="icon icon-angle-right icon-lg icon-pl"></i></div>
        <h4 class="title">密码算法实验</h4>
      </a>
    </div>
  
</nav>



    














</article>

<div id="reward" class="page-modal reward-lay">
    <a class="close" href="javascript:;"><i class="icon icon-close"></i></a>
    <h3 class="reward-title">
        <i class="icon icon-quote-left"></i>
        🤠 请我喝可乐！
        <i class="icon icon-quote-right"></i>
    </h3>
    <div class="reward-content" style="width:50%">
        
        <div class="reward-code" style="text-align:center">
            <div style="width:300px;margin:0px auto;">
               <img id="rewardCode" style="width:50%;height:60%;display:block; margin:0px auto;" src="/img/alipay.jpg" alt="支付宝打赏二维码">
               <span style="display:inline-block; margin-bottom:20px;">0.88(支付宝 aliPay)</span>
               <img id="rewardCode" style="width:50%;height:60%;display:block; margin:0px auto;" src="/img/wechat.jpg" alt="微信打赏二维码">
               <span style="display:inline-block;">0.88(微信 weChat)</span>
            </div>
        </div>
    </div>
</div>



</div>

        <script>
!function(e,t,a){function n(){c(".heart{width: 10px;height: 10px;position: fixed;background: #f00;transform: rotate(45deg);-webkit-transform: rotate(45deg);-moz-transform: rotate(45deg);}.heart:after,.heart:before{content: '';width: inherit;height: inherit;background: inherit;border-radius: 50%;-webkit-border-radius: 50%;-moz-border-radius: 50%;position: fixed;}.heart:after{top: -5px;}.heart:before{left: -5px;}"),o(),r()}function r(){for(var e=0;e<d.length;e++)d[e].alpha<=0?(t.body.removeChild(d[e].el),d.splice(e,1)):(d[e].y--,d[e].scale+=.004,d[e].alpha-=.013,d[e].el.style.cssText="left:"+d[e].x+"px;top:"+d[e].y+"px;opacity:"+d[e].alpha+";transform:scale("+d[e].scale+","+d[e].scale+") rotate(45deg);background:"+d[e].color+";z-index:99999");requestAnimationFrame(r)}function o(){var t="function"==typeof e.onclick&&e.onclick;e.onclick=function(e){t&&t(),i(e)}}function i(e){var a=t.createElement("div");a.className="heart",d.push({el:a,x:e.clientX-5,y:e.clientY-5,scale:1,alpha:1,color:s()}),t.body.appendChild(a)}function c(e){var a=t.createElement("style");a.type="text/css";try{a.appendChild(t.createTextNode(e))}catch(t){a.styleSheet.cssText=e}t.getElementsByTagName("head")[0].appendChild(a)}function s(){return"rgb("+~~(255*Math.random())+","+~~(255*Math.random())+","+~~(255*Math.random())+")"}var d=[];e.requestAnimationFrame=function(){return e.requestAnimationFrame||e.webkitRequestAnimationFrame||e.mozRequestAnimationFrame||e.oRequestAnimationFrame||e.msRequestAnimationFrame||function(e){setTimeout(e,1e3/60)}}(),n()}(window,document);
</script>
<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
<script>
    function secondToDate(second) {
        if (!second) {
            return 0;
        }
        var time = new Array(0, 0, 0, 0, 0);
        if (second >= 365 * 24 * 3600) {
            time[0] = parseInt(second / (365 * 24 * 3600));
            second %= 365 * 24 * 3600;
        }
        if (second >= 24 * 3600) {
            time[1] = parseInt(second / (24 * 3600));
            second %= 24 * 3600;
        }
        if (second >= 3600) {
            time[2] = parseInt(second / 3600);
            second %= 3600;
        }
        if (second >= 60) {
            time[3] = parseInt(second / 60);
            second %= 60;
        }
        if (second > 0) {
            time[4] = second;
        }
        return time;
    }</script>
<script type="text/javascript" language="javascript">
    function setTime() {
        var create_time = Math.round(new Date(Date.UTC(2017, 08, 18, 11, 42, 23)).getTime() / 1000);
        var timestamp = Math.round((new Date().getTime() + 8 * 60 * 60 * 1000) / 1000);
        currentTime = secondToDate((timestamp - create_time));
        currentTimeHtml = 'Running：' + currentTime[0] + '年 ' + currentTime[1] + '天 '
                + currentTime[2] + '时 ' + currentTime[3] + '分 ' + currentTime[4]
                + '秒';
        document.getElementById("htmer_time").innerHTML = currentTimeHtml;
    }    setInterval(setTime, 1000);
</script>
<footer class="footer">
    <div class="top">
        

        <p>
          <span id="busuanzi_container_page_pv">
             [&nbsp;浏览量：&nbsp;<span id="busuanzi_value_page_pv"></span>&nbsp;]
          </span>
        </p>
    </div>
    <div class="bottom">
        <p>
        <span>BingZhenhuang &copy; 2017 - 2020</span>
            <span>
                
                Power by <a href="https://hhardyy.github.io/" target="_blank">zhen On August 8</a> 
            </span>
            <span id="htmer_time" "></span>
        </p>
    </div>
</footer>

    </main>
    <div class="mask" id="mask"></div>
<a href="javascript:;" id="gotop" class="waves-effect waves-circle waves-light"><span class="icon icon-lg icon-chevron-up"></span></a>



<div class="global-share" id="globalShare">
    <ul class="reset share-icons">
      <li>
        <a class="weibo share-sns" target="_blank" href="http://service.weibo.com/share/share.php?url=http://yoursite.com/2018/09/21/redux、react-router/&title=《redux、react-router》 — 小方块 - hhardyy.com&pic=http://yoursite.com/img/avatar.jpg" data-title="微博">
          <i class="icon icon-weibo"></i>
        </a>
      </li>
      <li>
        <a class="weixin share-sns wxFab" href="javascript:;" data-title="微信">
          <i class="icon icon-weixin"></i>
        </a>
      </li>
      <li>
        <a class="qq share-sns" target="_blank" href="http://connect.qq.com/widget/shareqq/index.html?url=http://yoursite.com/2018/09/21/redux、react-router/&title=《redux、react-router》 — 小方块 - hhardyy.com&source=redux状态管理，不光react可以用，vue，angular都可以用。
" data-title=" QQ">
          <i class="icon icon-qq"></i>
        </a>
      </li>
      <li>
        <a class="facebook share-sns" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=http://yoursite.com/2018/09/21/redux、react-router/" data-title=" Facebook">
          <i class="icon icon-facebook"></i>
        </a>
      </li>
      <li>
        <a class="twitter share-sns" target="_blank" href="https://twitter.com/intent/tweet?text=《redux、react-router》 — 小方块 - hhardyy.com&url=http://yoursite.com/2018/09/21/redux、react-router/&via=http://yoursite.com" data-title=" Twitter">
          <i class="icon icon-twitter"></i>
        </a>
      </li>
      <li>
        <a class="google share-sns" target="_blank" href="https://plus.google.com/share?url=http://yoursite.com/2018/09/21/redux、react-router/" data-title=" Google+">
          <i class="icon icon-google-plus"></i>
        </a>
      </li>
    </ul>
 </div>


<div class="page-modal wx-share" id="wxShare">
    <a class="close" href="javascript:;"><i class="icon icon-close"></i></a>
    <p>扫一扫，分享到微信</p>
    <img src="" alt="微信分享二维码">
</div>




    <script src="//cdn.bootcss.com/node-waves/0.7.4/waves.min.js"></script>
<script>
var BLOG = { ROOT: '/', SHARE: true, REWARD: true };


</script>

<script src="//unpkg.com/hexo-theme-material-indigo@latest/js/main.min.js"></script>


<div class="search-panel" id="search-panel">
    <ul class="search-result" id="search-result"></ul>
</div>
<template id="search-tpl">
<li class="item">
    <a href="{path}" class="waves-block waves-effect">
        <div class="title ellipsis" title="{title}">{title}</div>
        <div class="flex-row flex-middle">
            <div class="tags ellipsis">
                {tags}
            </div>
            <time class="flex-col time">{date}</time>
        </div>
    </a>
</li>
</template>

<script src="//unpkg.com/hexo-theme-material-indigo@latest/js/search.min.js" async></script>








<script>
(function() {
    var OriginTitile = document.title, titleTime;
    document.addEventListener('visibilitychange', function() {
        if (document.hidden) {
            document.title = '(•‾̑⌣‾̑•)✧˖°回来看我';
            clearTimeout(titleTime);
        } else {
            document.title = '(゜-゜)つロ欢迎回来';
            titleTime = setTimeout(function() {
                document.title = OriginTitile;
            },2000);
        }
    });
})();
</script>



</body>
</html>
